<template>
  <div>
    <el-dialog center title='会员编辑' :visible.sync="isShow" :close-on-press-escape="false" :before-close="offCheck">
      <el-form :model="memberInfo" :rules="rules" ref="memberForm">
        <el-form-item prop="phone" label="手机号" :label-width="formLabelWidth">
          <el-input v-model="memberInfo.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item prop="nickname" label="昵称" :label-width="formLabelWidth">
          <el-input v-model="memberInfo.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input v-model="memberInfo.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth">
          <el-switch v-model="memberInfo.status" active-color="#13ce66" inactive-color="#ccc" :active-value="1"
            :inactive-value="2">
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="offCheck">取 消</el-button>
        <el-button type="primary" @click="addCate">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 引入接口地址
import { memberInfo, memberEdit } from '@/request/api';
// 引入辅助性函数
import { mapActions } from 'vuex';
export default {
  props: ["isShow"],
  data() {
    return {
      memberInfo: {
        nickname: "",
        phone: "",
        password: "",
        status: 1,
      },
      formLabelWidth: "120px",
      rules: {
        title: [
          { required: true, message: "请输入轮播图名称", trigger: "blur" },
          { min: 2, max: 12, message: "长度在 2 到 12 个字符", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    // 点击取消
    offCheck() {
      // 子传父
      this.$emit("offCheck", false)
      // 清空表单信息
      this.$refs.memberForm.resetFields()
      this.memberInfo = {
        nickname: "",
        phone: "",
        password: "",
        status: 1,
      }
    },
    // 获取会员管理列表
    ...mapActions({
      getMemberList: "member/getMemberList_Action"
    }),
    // 会员管理数据回显
    getOneMember(uid) {
      // 调用查询一条会员列表信息接口
      memberInfo({ uid }).then(res => {
        if (res.code == 200) {
          // 进行数据回显
          this.memberInfo = res.list
          this.memberInfo.uid = uid
        }
      })
    },
    //点击确定
    addCate() {
      this.$refs.memberForm.validate((flag) => {
        if (flag) {
          //调用编辑接口
          memberEdit(this.memberInfo).then(res => {
            if (res.code == 200) {
              this.$message.success(res.msg);
              // 重新渲染会员列表
              this.getMemberList()
              this.offCheck()
            }
          })
        } else {
          // 错误提示
          this.$message.error("请输入正确的内容");
        }
      });
    },
  },
};
</script>

<style scoped>
</style>
